﻿using System;

namespace NMA.Infrastructure.NHibernate.OrderByExpression
{
    using NMA.Domain.Model;
    using NMA.Domain.Model.Contract;
    using NMA.Infrastructure.NHibernate.OrderByExpression.Category;

    public class OrderByExpressionFactory : IOrderByExpressionFactory
    {
        public Func<ICategory, object> CreateCategorySearchOrderBy(SearchCategoryOrderByType orderType)
        {
            return new SearchCategoryOrderByExpression().CreatedCriteriaExpression(orderType);
        }

        public Func<ICategory, object> CreateCategorySearchOrderBy(string orderBy)
        {
            return new SearchCategoryOrderByExpression().CreatedCriteriaExpression(ConvertStringToType(orderBy));
        }

        private SearchCategoryOrderByType ConvertStringToType(string orderBy)
        {
            SearchCategoryOrderByType type = SearchCategoryOrderByType.Name;

            switch (orderBy)
            {
                case "Id":
                    type = SearchCategoryOrderByType.Id;
                    break;
                case "Name":
                    type = SearchCategoryOrderByType.Name;
                    break;
                case "CreatedUser":
                    type = SearchCategoryOrderByType.CreatedUser;
                    break;
                case "CreatedDate":
                    type = SearchCategoryOrderByType.CreatedDate;
                    break;
                default:
                    type = SearchCategoryOrderByType.Name;
                    break;
            }

            return type;
        }
    }
}